package graphes;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Serialisation {

	public static void serialise(Graphe g,String fichier)throws SerialisationException{
		try {
			FileOutputStream stream = new FileOutputStream(fichier);
			ObjectOutputStream oos = new ObjectOutputStream(stream);
			oos.writeObject(g);
			oos.flush();
			oos.close();
		} catch (IOException e) {
			e.printStackTrace();
			throw new SerialisationException();
		}
	}
	public static Graphe deSerialise(String fichier)throws SerialisationException{
		Graphe g=null;
		try {
		FileInputStream stream = new FileInputStream(fichier);
		ObjectInputStream ois = new ObjectInputStream(stream);
		g= (Graphe) ois.readObject();
		ois.close();
		} catch (IOException e) {
			e.printStackTrace();
			throw new SerialisationException();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new SerialisationException();
		}
		return g;
	}
}
